package com.room.search.web.rest;

import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.hasItem;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

import com.room.search.IntegrationTest;
import com.room.search.domain.RoomRentBasic;
import com.room.search.repository.RoomRentBasicRepository;
import com.room.search.service.dto.RoomRentBasicDTO;
import com.room.search.service.mapper.RoomRentBasicMapper;
import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.temporal.ChronoUnit;
import java.util.List;
import java.util.Random;
import java.util.concurrent.atomic.AtomicLong;
import javax.persistence.EntityManager;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.http.MediaType;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.transaction.annotation.Transactional;

/**
 * Integration tests for the {@link RoomRentBasicResource} REST controller.
 */
@IntegrationTest
@AutoConfigureMockMvc
@WithMockUser
class RoomRentBasicResourceIT {

    private static final LocalDate DEFAULT_CARE = LocalDate.ofEpochDay(0L);
    private static final LocalDate UPDATED_CARE = LocalDate.now(ZoneId.systemDefault());

    private static final String DEFAULT_PARKING = "AAAAAAAAAA";
    private static final String UPDATED_PARKING = "BBBBBBBBBB";

    private static final String DEFAULT_ELECTRICITY = "AAAAAAAAAA";
    private static final String UPDATED_ELECTRICITY = "BBBBBBBBBB";

    private static final String DEFAULT_LEASE = "AAAAAAAAAA";
    private static final String UPDATED_LEASE = "BBBBBBBBBB";

    private static final LocalDate DEFAULT_OCCUPANCY = LocalDate.ofEpochDay(0L);
    private static final LocalDate UPDATED_OCCUPANCY = LocalDate.now(ZoneId.systemDefault());

    private static final String DEFAULT_WATER = "AAAAAAAAAA";
    private static final String UPDATED_WATER = "BBBBBBBBBB";

    private static final String DEFAULT_GAS = "AAAAAAAAAA";
    private static final String UPDATED_GAS = "BBBBBBBBBB";

    private static final String DEFAULT_CREATED_BY = "AAAAAAAAAA";
    private static final String UPDATED_CREATED_BY = "BBBBBBBBBB";

    private static final Instant DEFAULT_CREATED_DATE = Instant.ofEpochMilli(0L);
    private static final Instant UPDATED_CREATED_DATE = Instant.now().truncatedTo(ChronoUnit.MILLIS);

    private static final String DEFAULT_LAST_MODIFIED_BY = "AAAAAAAAAA";
    private static final String UPDATED_LAST_MODIFIED_BY = "BBBBBBBBBB";

    private static final Instant DEFAULT_LAST_MODIFIED_DATE = Instant.ofEpochMilli(0L);
    private static final Instant UPDATED_LAST_MODIFIED_DATE = Instant.now().truncatedTo(ChronoUnit.MILLIS);

    private static final String ENTITY_API_URL = "/api/room-rent-basics";
    private static final String ENTITY_API_URL_ID = ENTITY_API_URL + "/{id}";

    private static Random random = new Random();
    private static AtomicLong count = new AtomicLong(random.nextInt() + (2 * Integer.MAX_VALUE));

    @Autowired
    private RoomRentBasicRepository roomRentBasicRepository;

    @Autowired
    private RoomRentBasicMapper roomRentBasicMapper;

    @Autowired
    private EntityManager em;

    @Autowired
    private MockMvc restRoomRentBasicMockMvc;

    private RoomRentBasic roomRentBasic;

    /**
     * Create an entity for this test.
     *
     * This is a static method, as tests for other entities might also need it,
     * if they test an entity which requires the current entity.
     */
    public static RoomRentBasic createEntity(EntityManager em) {
        RoomRentBasic roomRentBasic = new RoomRentBasic()
            .care(DEFAULT_CARE)
            .parking(DEFAULT_PARKING)
            .electricity(DEFAULT_ELECTRICITY)
            .lease(DEFAULT_LEASE)
            .occupancy(DEFAULT_OCCUPANCY)
            .water(DEFAULT_WATER)
            .gas(DEFAULT_GAS)
            .createdBy(DEFAULT_CREATED_BY)
            .createdDate(DEFAULT_CREATED_DATE)
            .lastModifiedBy(DEFAULT_LAST_MODIFIED_BY)
            .lastModifiedDate(DEFAULT_LAST_MODIFIED_DATE);
        return roomRentBasic;
    }

    /**
     * Create an updated entity for this test.
     *
     * This is a static method, as tests for other entities might also need it,
     * if they test an entity which requires the current entity.
     */
    public static RoomRentBasic createUpdatedEntity(EntityManager em) {
        RoomRentBasic roomRentBasic = new RoomRentBasic()
            .care(UPDATED_CARE)
            .parking(UPDATED_PARKING)
            .electricity(UPDATED_ELECTRICITY)
            .lease(UPDATED_LEASE)
            .occupancy(UPDATED_OCCUPANCY)
            .water(UPDATED_WATER)
            .gas(UPDATED_GAS)
            .createdBy(UPDATED_CREATED_BY)
            .createdDate(UPDATED_CREATED_DATE)
            .lastModifiedBy(UPDATED_LAST_MODIFIED_BY)
            .lastModifiedDate(UPDATED_LAST_MODIFIED_DATE);
        return roomRentBasic;
    }

    @BeforeEach
    public void initTest() {
        roomRentBasic = createEntity(em);
    }

    @Test
    @Transactional
    void createRoomRentBasic() throws Exception {
        int databaseSizeBeforeCreate = roomRentBasicRepository.findAll().size();
        // Create the RoomRentBasic
        RoomRentBasicDTO roomRentBasicDTO = roomRentBasicMapper.toDto(roomRentBasic);
        restRoomRentBasicMockMvc
            .perform(
                post(ENTITY_API_URL).contentType(MediaType.APPLICATION_JSON).content(TestUtil.convertObjectToJsonBytes(roomRentBasicDTO))
            )
            .andExpect(status().isCreated());

        // Validate the RoomRentBasic in the database
        List<RoomRentBasic> roomRentBasicList = roomRentBasicRepository.findAll();
        assertThat(roomRentBasicList).hasSize(databaseSizeBeforeCreate + 1);
        RoomRentBasic testRoomRentBasic = roomRentBasicList.get(roomRentBasicList.size() - 1);
        assertThat(testRoomRentBasic.getCare()).isEqualTo(DEFAULT_CARE);
        assertThat(testRoomRentBasic.getParking()).isEqualTo(DEFAULT_PARKING);
        assertThat(testRoomRentBasic.getElectricity()).isEqualTo(DEFAULT_ELECTRICITY);
        assertThat(testRoomRentBasic.getLease()).isEqualTo(DEFAULT_LEASE);
        assertThat(testRoomRentBasic.getOccupancy()).isEqualTo(DEFAULT_OCCUPANCY);
        assertThat(testRoomRentBasic.getWater()).isEqualTo(DEFAULT_WATER);
        assertThat(testRoomRentBasic.getGas()).isEqualTo(DEFAULT_GAS);
        assertThat(testRoomRentBasic.getCreatedBy()).isEqualTo(DEFAULT_CREATED_BY);
        assertThat(testRoomRentBasic.getCreatedDate()).isEqualTo(DEFAULT_CREATED_DATE);
        assertThat(testRoomRentBasic.getLastModifiedBy()).isEqualTo(DEFAULT_LAST_MODIFIED_BY);
        assertThat(testRoomRentBasic.getLastModifiedDate()).isEqualTo(DEFAULT_LAST_MODIFIED_DATE);
    }

    @Test
    @Transactional
    void createRoomRentBasicWithExistingId() throws Exception {
        // Create the RoomRentBasic with an existing ID
        roomRentBasic.setId(1L);
        RoomRentBasicDTO roomRentBasicDTO = roomRentBasicMapper.toDto(roomRentBasic);

        int databaseSizeBeforeCreate = roomRentBasicRepository.findAll().size();

        // An entity with an existing ID cannot be created, so this API call must fail
        restRoomRentBasicMockMvc
            .perform(
                post(ENTITY_API_URL).contentType(MediaType.APPLICATION_JSON).content(TestUtil.convertObjectToJsonBytes(roomRentBasicDTO))
            )
            .andExpect(status().isBadRequest());

        // Validate the RoomRentBasic in the database
        List<RoomRentBasic> roomRentBasicList = roomRentBasicRepository.findAll();
        assertThat(roomRentBasicList).hasSize(databaseSizeBeforeCreate);
    }

    @Test
    @Transactional
    void getAllRoomRentBasics() throws Exception {
        // Initialize the database
        roomRentBasicRepository.saveAndFlush(roomRentBasic);

        // Get all the roomRentBasicList
        restRoomRentBasicMockMvc
            .perform(get(ENTITY_API_URL + "?sort=id,desc"))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$.[*].id").value(hasItem(roomRentBasic.getId().intValue())))
            .andExpect(jsonPath("$.[*].care").value(hasItem(DEFAULT_CARE.toString())))
            .andExpect(jsonPath("$.[*].parking").value(hasItem(DEFAULT_PARKING)))
            .andExpect(jsonPath("$.[*].electricity").value(hasItem(DEFAULT_ELECTRICITY)))
            .andExpect(jsonPath("$.[*].lease").value(hasItem(DEFAULT_LEASE)))
            .andExpect(jsonPath("$.[*].occupancy").value(hasItem(DEFAULT_OCCUPANCY.toString())))
            .andExpect(jsonPath("$.[*].water").value(hasItem(DEFAULT_WATER)))
            .andExpect(jsonPath("$.[*].gas").value(hasItem(DEFAULT_GAS)))
            .andExpect(jsonPath("$.[*].createdBy").value(hasItem(DEFAULT_CREATED_BY)))
            .andExpect(jsonPath("$.[*].createdDate").value(hasItem(DEFAULT_CREATED_DATE.toString())))
            .andExpect(jsonPath("$.[*].lastModifiedBy").value(hasItem(DEFAULT_LAST_MODIFIED_BY)))
            .andExpect(jsonPath("$.[*].lastModifiedDate").value(hasItem(DEFAULT_LAST_MODIFIED_DATE.toString())));
    }

    @Test
    @Transactional
    void getRoomRentBasic() throws Exception {
        // Initialize the database
        roomRentBasicRepository.saveAndFlush(roomRentBasic);

        // Get the roomRentBasic
        restRoomRentBasicMockMvc
            .perform(get(ENTITY_API_URL_ID, roomRentBasic.getId()))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$.id").value(roomRentBasic.getId().intValue()))
            .andExpect(jsonPath("$.care").value(DEFAULT_CARE.toString()))
            .andExpect(jsonPath("$.parking").value(DEFAULT_PARKING))
            .andExpect(jsonPath("$.electricity").value(DEFAULT_ELECTRICITY))
            .andExpect(jsonPath("$.lease").value(DEFAULT_LEASE))
            .andExpect(jsonPath("$.occupancy").value(DEFAULT_OCCUPANCY.toString()))
            .andExpect(jsonPath("$.water").value(DEFAULT_WATER))
            .andExpect(jsonPath("$.gas").value(DEFAULT_GAS))
            .andExpect(jsonPath("$.createdBy").value(DEFAULT_CREATED_BY))
            .andExpect(jsonPath("$.createdDate").value(DEFAULT_CREATED_DATE.toString()))
            .andExpect(jsonPath("$.lastModifiedBy").value(DEFAULT_LAST_MODIFIED_BY))
            .andExpect(jsonPath("$.lastModifiedDate").value(DEFAULT_LAST_MODIFIED_DATE.toString()));
    }

    @Test
    @Transactional
    void getNonExistingRoomRentBasic() throws Exception {
        // Get the roomRentBasic
        restRoomRentBasicMockMvc.perform(get(ENTITY_API_URL_ID, Long.MAX_VALUE)).andExpect(status().isNotFound());
    }

    @Test
    @Transactional
    void putNewRoomRentBasic() throws Exception {
        // Initialize the database
        roomRentBasicRepository.saveAndFlush(roomRentBasic);

        int databaseSizeBeforeUpdate = roomRentBasicRepository.findAll().size();

        // Update the roomRentBasic
        RoomRentBasic updatedRoomRentBasic = roomRentBasicRepository.findById(roomRentBasic.getId()).get();
        // Disconnect from session so that the updates on updatedRoomRentBasic are not directly saved in db
        em.detach(updatedRoomRentBasic);
        updatedRoomRentBasic
            .care(UPDATED_CARE)
            .parking(UPDATED_PARKING)
            .electricity(UPDATED_ELECTRICITY)
            .lease(UPDATED_LEASE)
            .occupancy(UPDATED_OCCUPANCY)
            .water(UPDATED_WATER)
            .gas(UPDATED_GAS)
            .createdBy(UPDATED_CREATED_BY)
            .createdDate(UPDATED_CREATED_DATE)
            .lastModifiedBy(UPDATED_LAST_MODIFIED_BY)
            .lastModifiedDate(UPDATED_LAST_MODIFIED_DATE);
        RoomRentBasicDTO roomRentBasicDTO = roomRentBasicMapper.toDto(updatedRoomRentBasic);

        restRoomRentBasicMockMvc
            .perform(
                put(ENTITY_API_URL_ID, roomRentBasicDTO.getId())
                    .contentType(MediaType.APPLICATION_JSON)
                    .content(TestUtil.convertObjectToJsonBytes(roomRentBasicDTO))
            )
            .andExpect(status().isOk());

        // Validate the RoomRentBasic in the database
        List<RoomRentBasic> roomRentBasicList = roomRentBasicRepository.findAll();
        assertThat(roomRentBasicList).hasSize(databaseSizeBeforeUpdate);
        RoomRentBasic testRoomRentBasic = roomRentBasicList.get(roomRentBasicList.size() - 1);
        assertThat(testRoomRentBasic.getCare()).isEqualTo(UPDATED_CARE);
        assertThat(testRoomRentBasic.getParking()).isEqualTo(UPDATED_PARKING);
        assertThat(testRoomRentBasic.getElectricity()).isEqualTo(UPDATED_ELECTRICITY);
        assertThat(testRoomRentBasic.getLease()).isEqualTo(UPDATED_LEASE);
        assertThat(testRoomRentBasic.getOccupancy()).isEqualTo(UPDATED_OCCUPANCY);
        assertThat(testRoomRentBasic.getWater()).isEqualTo(UPDATED_WATER);
        assertThat(testRoomRentBasic.getGas()).isEqualTo(UPDATED_GAS);
        assertThat(testRoomRentBasic.getCreatedBy()).isEqualTo(UPDATED_CREATED_BY);
        assertThat(testRoomRentBasic.getCreatedDate()).isEqualTo(UPDATED_CREATED_DATE);
        assertThat(testRoomRentBasic.getLastModifiedBy()).isEqualTo(UPDATED_LAST_MODIFIED_BY);
        assertThat(testRoomRentBasic.getLastModifiedDate()).isEqualTo(UPDATED_LAST_MODIFIED_DATE);
    }

    @Test
    @Transactional
    void putNonExistingRoomRentBasic() throws Exception {
        int databaseSizeBeforeUpdate = roomRentBasicRepository.findAll().size();
        roomRentBasic.setId(count.incrementAndGet());

        // Create the RoomRentBasic
        RoomRentBasicDTO roomRentBasicDTO = roomRentBasicMapper.toDto(roomRentBasic);

        // If the entity doesn't have an ID, it will throw BadRequestAlertException
        restRoomRentBasicMockMvc
            .perform(
                put(ENTITY_API_URL_ID, roomRentBasicDTO.getId())
                    .contentType(MediaType.APPLICATION_JSON)
                    .content(TestUtil.convertObjectToJsonBytes(roomRentBasicDTO))
            )
            .andExpect(status().isBadRequest());

        // Validate the RoomRentBasic in the database
        List<RoomRentBasic> roomRentBasicList = roomRentBasicRepository.findAll();
        assertThat(roomRentBasicList).hasSize(databaseSizeBeforeUpdate);
    }

    @Test
    @Transactional
    void putWithIdMismatchRoomRentBasic() throws Exception {
        int databaseSizeBeforeUpdate = roomRentBasicRepository.findAll().size();
        roomRentBasic.setId(count.incrementAndGet());

        // Create the RoomRentBasic
        RoomRentBasicDTO roomRentBasicDTO = roomRentBasicMapper.toDto(roomRentBasic);

        // If url ID doesn't match entity ID, it will throw BadRequestAlertException
        restRoomRentBasicMockMvc
            .perform(
                put(ENTITY_API_URL_ID, count.incrementAndGet())
                    .contentType(MediaType.APPLICATION_JSON)
                    .content(TestUtil.convertObjectToJsonBytes(roomRentBasicDTO))
            )
            .andExpect(status().isBadRequest());

        // Validate the RoomRentBasic in the database
        List<RoomRentBasic> roomRentBasicList = roomRentBasicRepository.findAll();
        assertThat(roomRentBasicList).hasSize(databaseSizeBeforeUpdate);
    }

    @Test
    @Transactional
    void putWithMissingIdPathParamRoomRentBasic() throws Exception {
        int databaseSizeBeforeUpdate = roomRentBasicRepository.findAll().size();
        roomRentBasic.setId(count.incrementAndGet());

        // Create the RoomRentBasic
        RoomRentBasicDTO roomRentBasicDTO = roomRentBasicMapper.toDto(roomRentBasic);

        // If url ID doesn't match entity ID, it will throw BadRequestAlertException
        restRoomRentBasicMockMvc
            .perform(
                put(ENTITY_API_URL).contentType(MediaType.APPLICATION_JSON).content(TestUtil.convertObjectToJsonBytes(roomRentBasicDTO))
            )
            .andExpect(status().isMethodNotAllowed());

        // Validate the RoomRentBasic in the database
        List<RoomRentBasic> roomRentBasicList = roomRentBasicRepository.findAll();
        assertThat(roomRentBasicList).hasSize(databaseSizeBeforeUpdate);
    }

    @Test
    @Transactional
    void partialUpdateRoomRentBasicWithPatch() throws Exception {
        // Initialize the database
        roomRentBasicRepository.saveAndFlush(roomRentBasic);

        int databaseSizeBeforeUpdate = roomRentBasicRepository.findAll().size();

        // Update the roomRentBasic using partial update
        RoomRentBasic partialUpdatedRoomRentBasic = new RoomRentBasic();
        partialUpdatedRoomRentBasic.setId(roomRentBasic.getId());

        partialUpdatedRoomRentBasic
            .care(UPDATED_CARE)
            .parking(UPDATED_PARKING)
            .occupancy(UPDATED_OCCUPANCY)
            .water(UPDATED_WATER)
            .createdBy(UPDATED_CREATED_BY);

        restRoomRentBasicMockMvc
            .perform(
                patch(ENTITY_API_URL_ID, partialUpdatedRoomRentBasic.getId())
                    .contentType("application/merge-patch+json")
                    .content(TestUtil.convertObjectToJsonBytes(partialUpdatedRoomRentBasic))
            )
            .andExpect(status().isOk());

        // Validate the RoomRentBasic in the database
        List<RoomRentBasic> roomRentBasicList = roomRentBasicRepository.findAll();
        assertThat(roomRentBasicList).hasSize(databaseSizeBeforeUpdate);
        RoomRentBasic testRoomRentBasic = roomRentBasicList.get(roomRentBasicList.size() - 1);
        assertThat(testRoomRentBasic.getCare()).isEqualTo(UPDATED_CARE);
        assertThat(testRoomRentBasic.getParking()).isEqualTo(UPDATED_PARKING);
        assertThat(testRoomRentBasic.getElectricity()).isEqualTo(DEFAULT_ELECTRICITY);
        assertThat(testRoomRentBasic.getLease()).isEqualTo(DEFAULT_LEASE);
        assertThat(testRoomRentBasic.getOccupancy()).isEqualTo(UPDATED_OCCUPANCY);
        assertThat(testRoomRentBasic.getWater()).isEqualTo(UPDATED_WATER);
        assertThat(testRoomRentBasic.getGas()).isEqualTo(DEFAULT_GAS);
        assertThat(testRoomRentBasic.getCreatedBy()).isEqualTo(UPDATED_CREATED_BY);
        assertThat(testRoomRentBasic.getCreatedDate()).isEqualTo(DEFAULT_CREATED_DATE);
        assertThat(testRoomRentBasic.getLastModifiedBy()).isEqualTo(DEFAULT_LAST_MODIFIED_BY);
        assertThat(testRoomRentBasic.getLastModifiedDate()).isEqualTo(DEFAULT_LAST_MODIFIED_DATE);
    }

    @Test
    @Transactional
    void fullUpdateRoomRentBasicWithPatch() throws Exception {
        // Initialize the database
        roomRentBasicRepository.saveAndFlush(roomRentBasic);

        int databaseSizeBeforeUpdate = roomRentBasicRepository.findAll().size();

        // Update the roomRentBasic using partial update
        RoomRentBasic partialUpdatedRoomRentBasic = new RoomRentBasic();
        partialUpdatedRoomRentBasic.setId(roomRentBasic.getId());

        partialUpdatedRoomRentBasic
            .care(UPDATED_CARE)
            .parking(UPDATED_PARKING)
            .electricity(UPDATED_ELECTRICITY)
            .lease(UPDATED_LEASE)
            .occupancy(UPDATED_OCCUPANCY)
            .water(UPDATED_WATER)
            .gas(UPDATED_GAS)
            .createdBy(UPDATED_CREATED_BY)
            .createdDate(UPDATED_CREATED_DATE)
            .lastModifiedBy(UPDATED_LAST_MODIFIED_BY)
            .lastModifiedDate(UPDATED_LAST_MODIFIED_DATE);

        restRoomRentBasicMockMvc
            .perform(
                patch(ENTITY_API_URL_ID, partialUpdatedRoomRentBasic.getId())
                    .contentType("application/merge-patch+json")
                    .content(TestUtil.convertObjectToJsonBytes(partialUpdatedRoomRentBasic))
            )
            .andExpect(status().isOk());

        // Validate the RoomRentBasic in the database
        List<RoomRentBasic> roomRentBasicList = roomRentBasicRepository.findAll();
        assertThat(roomRentBasicList).hasSize(databaseSizeBeforeUpdate);
        RoomRentBasic testRoomRentBasic = roomRentBasicList.get(roomRentBasicList.size() - 1);
        assertThat(testRoomRentBasic.getCare()).isEqualTo(UPDATED_CARE);
        assertThat(testRoomRentBasic.getParking()).isEqualTo(UPDATED_PARKING);
        assertThat(testRoomRentBasic.getElectricity()).isEqualTo(UPDATED_ELECTRICITY);
        assertThat(testRoomRentBasic.getLease()).isEqualTo(UPDATED_LEASE);
        assertThat(testRoomRentBasic.getOccupancy()).isEqualTo(UPDATED_OCCUPANCY);
        assertThat(testRoomRentBasic.getWater()).isEqualTo(UPDATED_WATER);
        assertThat(testRoomRentBasic.getGas()).isEqualTo(UPDATED_GAS);
        assertThat(testRoomRentBasic.getCreatedBy()).isEqualTo(UPDATED_CREATED_BY);
        assertThat(testRoomRentBasic.getCreatedDate()).isEqualTo(UPDATED_CREATED_DATE);
        assertThat(testRoomRentBasic.getLastModifiedBy()).isEqualTo(UPDATED_LAST_MODIFIED_BY);
        assertThat(testRoomRentBasic.getLastModifiedDate()).isEqualTo(UPDATED_LAST_MODIFIED_DATE);
    }

    @Test
    @Transactional
    void patchNonExistingRoomRentBasic() throws Exception {
        int databaseSizeBeforeUpdate = roomRentBasicRepository.findAll().size();
        roomRentBasic.setId(count.incrementAndGet());

        // Create the RoomRentBasic
        RoomRentBasicDTO roomRentBasicDTO = roomRentBasicMapper.toDto(roomRentBasic);

        // If the entity doesn't have an ID, it will throw BadRequestAlertException
        restRoomRentBasicMockMvc
            .perform(
                patch(ENTITY_API_URL_ID, roomRentBasicDTO.getId())
                    .contentType("application/merge-patch+json")
                    .content(TestUtil.convertObjectToJsonBytes(roomRentBasicDTO))
            )
            .andExpect(status().isBadRequest());

        // Validate the RoomRentBasic in the database
        List<RoomRentBasic> roomRentBasicList = roomRentBasicRepository.findAll();
        assertThat(roomRentBasicList).hasSize(databaseSizeBeforeUpdate);
    }

    @Test
    @Transactional
    void patchWithIdMismatchRoomRentBasic() throws Exception {
        int databaseSizeBeforeUpdate = roomRentBasicRepository.findAll().size();
        roomRentBasic.setId(count.incrementAndGet());

        // Create the RoomRentBasic
        RoomRentBasicDTO roomRentBasicDTO = roomRentBasicMapper.toDto(roomRentBasic);

        // If url ID doesn't match entity ID, it will throw BadRequestAlertException
        restRoomRentBasicMockMvc
            .perform(
                patch(ENTITY_API_URL_ID, count.incrementAndGet())
                    .contentType("application/merge-patch+json")
                    .content(TestUtil.convertObjectToJsonBytes(roomRentBasicDTO))
            )
            .andExpect(status().isBadRequest());

        // Validate the RoomRentBasic in the database
        List<RoomRentBasic> roomRentBasicList = roomRentBasicRepository.findAll();
        assertThat(roomRentBasicList).hasSize(databaseSizeBeforeUpdate);
    }

    @Test
    @Transactional
    void patchWithMissingIdPathParamRoomRentBasic() throws Exception {
        int databaseSizeBeforeUpdate = roomRentBasicRepository.findAll().size();
        roomRentBasic.setId(count.incrementAndGet());

        // Create the RoomRentBasic
        RoomRentBasicDTO roomRentBasicDTO = roomRentBasicMapper.toDto(roomRentBasic);

        // If url ID doesn't match entity ID, it will throw BadRequestAlertException
        restRoomRentBasicMockMvc
            .perform(
                patch(ENTITY_API_URL)
                    .contentType("application/merge-patch+json")
                    .content(TestUtil.convertObjectToJsonBytes(roomRentBasicDTO))
            )
            .andExpect(status().isMethodNotAllowed());

        // Validate the RoomRentBasic in the database
        List<RoomRentBasic> roomRentBasicList = roomRentBasicRepository.findAll();
        assertThat(roomRentBasicList).hasSize(databaseSizeBeforeUpdate);
    }

    @Test
    @Transactional
    void deleteRoomRentBasic() throws Exception {
        // Initialize the database
        roomRentBasicRepository.saveAndFlush(roomRentBasic);

        int databaseSizeBeforeDelete = roomRentBasicRepository.findAll().size();

        // Delete the roomRentBasic
        restRoomRentBasicMockMvc
            .perform(delete(ENTITY_API_URL_ID, roomRentBasic.getId()).accept(MediaType.APPLICATION_JSON))
            .andExpect(status().isNoContent());

        // Validate the database contains one less item
        List<RoomRentBasic> roomRentBasicList = roomRentBasicRepository.findAll();
        assertThat(roomRentBasicList).hasSize(databaseSizeBeforeDelete - 1);
    }
}
